package com.mb.app.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.mb.app.domain.TbUserAuthInfo;
import com.mb.app.domain.TbUserAuthInfo;
import com.mb.app.dao.TbUserAuthInfoMapper;
import com.mb.app.service.ITbUserAuthInfoService;
import com.mb.common.config.CommonConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户身份证认证信息  服务实现类
 * </p>
 *
 * @author liliping
 * @since 2019-03-21
 */
@Service
@Slf4j
public class TbUserAuthInfoServiceImpl extends ServiceImpl<TbUserAuthInfoMapper, TbUserAuthInfo> implements ITbUserAuthInfoService {

    @Autowired
    private CommonConfig commonConfig;

    @Override
    public List<TbUserAuthInfo> queryList(Map<String, Object> map) {
        List<TbUserAuthInfo> list = this.baseMapper.lst(map);
        return list;
    }

    @Override
    public int count(Map<String, Object> map) {
        return this.baseMapper.countt(map);
    }


    @Override
    public int update(TbUserAuthInfo TbUserAuthInfo) {
        try {
            TbUserAuthInfo TbUserAuthInfo1 = new TbUserAuthInfo();
            TbUserAuthInfo1.setId(TbUserAuthInfo.getId());
            TbUserAuthInfo1.setDataStatus(1);
            TbUserAuthInfo TbUserAuthInfoDO = this.baseMapper.selectOne(TbUserAuthInfo1);
            if(TbUserAuthInfoDO != null){
                TbUserAuthInfo.setAuditTime(new Date());
                this.baseMapper.updateById(TbUserAuthInfo);
            }
        } catch (Exception e) {
            log.error("update Exception",e);
        }
        return 0;
    }

    @Override
    public TbUserAuthInfo getDtl(Long productId) {
        TbUserAuthInfo TbUserAuthInfo = this.baseMapper.selectById(productId);
        if(TbUserAuthInfo != null) {
            if (StringUtils.isNotEmpty(TbUserAuthInfo.getIdcardFrontImg())) {
                TbUserAuthInfo.setIdcardFrontImg(commonConfig.getImgDomain()+TbUserAuthInfo.getIdcardFrontImg());
            }
            if (StringUtils.isNotEmpty(TbUserAuthInfo.getIdcardBackImg())) {
                TbUserAuthInfo.setIdcardBackImg(commonConfig.getImgDomain()+TbUserAuthInfo.getIdcardBackImg());
            }
            if (StringUtils.isNotEmpty(TbUserAuthInfo.getHoldIdcardImg())) {
                TbUserAuthInfo.setHoldIdcardImg(commonConfig.getImgDomain()+TbUserAuthInfo.getHoldIdcardImg());
            }
        }
        return TbUserAuthInfo;
    }

}
